const express = require('express');
const path = require('path');
const { connectDB } = require('./src/config/database');

// 导入配置好的应用
const expressApp = require('./src/app');
const config = require('./src/config/app');

// 连接数据库
connectDB();

// 启动服务器
const server = expressApp.listen(config.port, () => {
  console.log(`服务器正在运行在 http://localhost:${config.port}`);
  console.log(`环境: ${config.environment}`);
});

// 优雅关闭
process.on('SIGINT', () => {
  console.log('\n正在关闭服务器...');
  server.close(() => {
    console.log('服务器已关闭');
    process.exit(0);
  });
});